package edu.zut.main.socket;

import java.net.InetAddress;
import java.net.UnknownHostException;

public class IPDemo {

    public static void main(String[] args) throws UnknownHostException {

        //ip  根据主机名获取ip对象
        InetAddress inetAddress = InetAddress.getByName("www.baidu.com");
        //获取ip中相关信息
        String hostAddress = inetAddress.getHostAddress();
        System.out.println("hostAddress = " + hostAddress);
        String hostName = inetAddress.getHostName();
        System.out.println("hostName = " + hostName);
        //获取本地注解的ip对象
        InetAddress localHost = InetAddress.getLocalHost();
        System.out.println("localHost.getHostAddress() = " + localHost.getHostAddress());
        System.out.println("localHost.getHostName() = " + localHost.getHostName());

    }


}
